
package com.networklib.task.impl;

import android.content.Context;

import com.networklib.TaskResult;
import com.networklib.http.ResponseResult;
import com.networklib.http.exception.NetException;
import com.networklib.http.impl.post.SinglePostHttpRequestImpl;
import com.networklib.http.other.HttpMethod;
import com.networklib.task.TaskResultCode;

import java.io.File;
import java.io.IOException;

public class UploadFileTask extends SimpleHttpTask {
    private final String mMimeType;
    private final File mUploadFile;

    public UploadFileTask(Context context, String url, String mimeType, String fileName, File file) throws NetException {
        super(context,url, HttpMethod.POST, file);
        this.mMimeType = mimeType;
        this.mUploadFile = file;
    }

    public boolean before(TaskResult taskResult) {
        return super.before(taskResult);
    }

    @Override
    protected TaskResult doExecute(TaskResult taskResult) {
        try {
            SinglePostHttpRequestImpl singlePostHttpRequest = (SinglePostHttpRequestImpl) request;
            ResponseResult execute = request.execute();
            taskResult.setResultCode(TaskResultCode.SUCCESS);
            taskResult.setResult(execute.getResponse());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return taskResult;
    }
}
